﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
namespace SchoolManagementSystem.Details
{
    public partial class Payment_MethodUC : DetailUC
    {
        public Payment_MethodUC()
        {
            InitializeComponent();
            this.ObjectName = "phương thức thanh toán";
            this.Code = "PaymentMethod";
            this.Type = new Payment_Method();
        }


        protected override long DetailDisplay()
        {
            Payment_Method data = new Payment_Method();
            if (ID > 0)
            {
                data = (Payment_Method)RegisterService.RegisterServices.PaymentMethodService.GetByID(ID);
            }

            txtname.Text = data.Name;
            txtnote.Text = data.Note;
            txtcode.Text = data.Code;
            ckactive.Checked = data.Active;

            return ID;

        }

        protected override long Save()
        {
            Payment_Method data = new Payment_Method();
            if (ID > 0)
            {
                data = (Payment_Method)RegisterService.RegisterServices.PaymentMethodService.GetByID(ID);

            }
            data.Code = txtcode.Text;
            data.Name = txtname.Text;
            data.Note = txtnote.Text;
            data.Active = ckactive.Checked;

            ID = RegisterService.RegisterServices.PaymentMethodService.Save(data);

            return ID;
        }


        public override bool Delete(long SelectedID)
        {
            if (SelectedID == 1 || SelectedID == 2)
            {
                ErrorMess = "Không thể xóa dữ liệu mặc định này";
                return false;
            }
            else
            {
                return RegisterService.RegisterServices.PaymentMethodService.Delete(RegisterService.RegisterServices.PaymentMethodService.GetByID(SelectedID));
            }
        }

        private void Payment_MethodUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }
    }
}
